how i write a 0`s or 1`s to binary file in bits not in bytes how can i do that
how i write a 0`s or 1`s to binary file in bits not in bytes how can i do that
Collapse
X
-
Tags: None
-
you could use bit fields to pack bits into a byte then write the byte to a binary file
-
You don't even need bit fields. Use an unsigned int. A 5 is a binary 101. In a 32-bit unsigned int the bits would be 000000000000000 000000000000001 01. If you write the int, that's the binary pattern in your file.
All you need do is find the integer value that matches the bit pattern you want and write that out.
You can never write just one bit. The I/O is byte sized.Comment
Comment